import cors from '@koa/cors'
import 'dotenv/config'
import Koa from 'koa'
import { koaBody } from 'koa-body'
import staticServe from 'koa-static'
import './configs/runtimeConfig'
import { auth } from './middlewares/auth'
import './models/index'
import { registerRouter } from './routers'
// import './test'

const app = new Koa()

app.use(cors())

// app.use((ctx, next) => {
//     console.log(ctx.url)
//     next()
// })

app.use(staticServe('./public'))

app.use(
    koaBody({
        // multipart: true,
        // formidable: {
        //     uploadDir: './public/uploads',
        //     keepExtensions: true
        // }
    })
)

app.use(auth)

registerRouter(app)

app.listen(3000, () => {
    console.log('Server is running at http://localhost:3000')
})
